<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>开启头部工具栏 - 数据表格</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="${pageContext.request.contextPath }/back/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="${pageContext.request.contextPath }/back/style/admin.css" media="all">
</head>
<body>

  <div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
      <a lay-href="">主页</a>
      <a><cite>组件</cite></a>
      <a><cite>数据表格</cite></a>
      <a><cite>开启头部工具栏</cite></a>
    </div>
  </div>
  
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">预约</div>
          <div class="layui-card-body">
          	<div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">审核状态</label>
            <div class="layui-input-block">
              <select name="role">
                <option value="0">待审核</option>
                <option value="1">已通过</option>
              </select>
            </div>
           </div>
          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
        </div>
      </div>
      
            <table class="layui-hide" id="test-table-toolbar" lay-filter="test-table-toolbar"></table>
            
            <script type="text/html" id="test-table-toolbar-toolbarDemo">
              <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
                <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
                <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
              </div>
            </script>
            <script type="text/html" id="buttonTpl">
              {{#  if(d.estatus == 0){ }}
              <button class="layui-btn layui-btn-disabled layui-btn-xs">已取消</button>
              {{# } else if(d.estatus == 1){ }}
              <input type="checkbox" lay-filter="switch" name="switch" value='0' lay-skin="switch" lay-text="通过|待审核">
              {{#  } else{ }}
              <input type="checkbox" lay-filter="switch" name="switch" value='1' lay-skin="switch" lay-text="通过|待审核" checked="checked">
              {{#  } }}
            </script>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="${pageContext.request.contextPath }/back/layui/layui.js"></script>
  <script>
  layui.config({
    base: '${pageContext.request.contextPath }/back/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table'], function(){
    var admin = layui.admin
    form = layui.form,
    jquery = layui.jquery,
    layer = layui.layer,
    table = layui.table;
  
    table.render({
      elem: '#test-table-toolbar'
      ,url: '${pageContext.request.contextPath }/viewEngageInfo/allEngage'
      ,toolbar: '#test-table-toolbar-toolbarDemo'
      ,title: '预约信息'
      ,cols: [[
          {type: 'checkbox', fixed: 'left'}
	      ,{field:'eId', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
	      ,{field:'userName', title:'用户名', width:120}
	      ,{field:'userTel', title:'手机号',width:120}
          ,{field:'userIDC', title:'身份证号', width:120}
	      ,{field:'rtName', title:'房间类型', width:100}
	      ,{field:'rtPrice', title:'价格', width:80}
	      ,{field:'roomNum', title:'房间号', width:80}
	      ,{field:'btime', title:'开始时间', width:120}
	      ,{field:'ktime', title:'持续时间', width:120}
	      ,{field:'etime', title:'结束时间', width:120}
	      ,{field:'remark', title:'备注', width:180}
        ,{field: 'estatus', title:'预约状态', templet: '#buttonTpl', fixed: 'right', width: 120, align: 'center'}
      ]]
      ,page: true
      ,limit:10
    });
    
    //头工具栏事件
    table.on('toolbar(test-table-toolbar)', function(obj){
      var checkStatus = table.checkStatus(obj.config.id);
      switch(obj.event){
        case 'getCheckData':
          var data = checkStatus.data;
          layer.alert(JSON.stringify(data));
        break;
        case 'getCheckLength':
          var data = checkStatus.data;
          layer.msg('选中了：'+ data.length + ' 个');
        break;
        case 'isAll':
          layer.msg(checkStatus.isAll ? '全选': '未全选');
        break;
      };
    });
  });
  layui.use(['form', 'jquery', 'layer'], function () {

            var form = layui.form;
            var jquery = layui.jquery;
            var layer = layui.layer;
            //监听开关事件
            form.on('switch(switch)', function (data) {

                var contexts;
                var x = data.elem.checked;//判断开关状态
                if (x==true) {
                    contexts = "你确定要通过预约吗";
                } else {
                    contexts = "你确定要取消预约么";
                }
                layer.open({
                    content: contexts
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        data.elem.checked = x;
                        form.render();
						console.log(x);
						//x为true  status=1
                        layer.close(index);
                        //按钮【按钮一】的回调
                    }
                    , btn2: function (index, layero) {
                        //按钮【按钮二】的回调
                        data.elem.checked = !x;
                        form.render();
                        layer.close(index);
                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                    , cancel: function () {
                        //右上角关闭回调
                        data.elem.checked = !x;
                        form.render();
                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                });
                return false;
            });
        });
  </script>
</body>
</html>